// projectile.h

#ifndef projectile_h
#define projectile_h

#include <gl/gl.h>
#include <gl/glu.h>

#include "gmath.h"

class Projectile {
public:
    Vector3 pos, vel;			// position and velocity of projectile

    GLUquadricObj* quadric;

    Projectile(Vector3 initPos, Vector3 dir) {
        pos = initPos;
        vel = dir;

		vel.scale(300);					// scale the initial speed to 100 ft/s

        quadric = gluNewQuadric();
    }

    ~Projectile() {
        if (quadric != NULL) {
            gluDeleteQuadric(quadric);
            quadric = NULL;
        }
    }

    void Update(float dt) 
	{
		Vector3 initVel = vel;
        Vector3 acceleration;

		//EQTN: Vf = Vi + at
		acceleration.set(0, -32.2, 0);				  // acceleration (x,y,z)=(0,-2,0)
		acceleration.scale(dt);
		vel = Add(vel, acceleration);              //velocity = vvelocity + acceleration

		//EQTN: newPos = oldPos + 0.5 * (Vf + Vi) * dt
		vel = Add(vel, initVel); //Vf + Vi
		//(Vf + Vi) * dt
		vel.scale(dt);                           //this is velocity= velocity*time
        vel.scale(0.5); //0.5 * (Vf + Vi) * dt
        pos = Add(pos, vel);                    //updates position = position + vel
    }

    void Render() {
        // draw the sphere in its updated position
		glPushMatrix();

        glTranslatef(pos.x, pos.y, pos.z);

        glColor3f(0, 1, 0);
        gluSphere(quadric, 1.0f, 10, 10);

		glPopMatrix();
    }
};

#endif